#include <iostream>

using namespace std;

class Solution {
public:
	int reverse(int x) {
		int min=0x80000000;
		int max=0x7fffffff;

		int r=x;
		int v=0;

		while(r!=0){
			if((v>0&&v>(max-r%10)/10)||(v<0&&v<(min-r%10)/10))
			return 0;

			v=10*v+r%10;
			r=r/10;
		}
		return v;
	}
};

int main(){

	Solution solution;
	int value;
	while(true){
		cin>>value;
		cout<<solution.reverse(value)<<endl;
	}
}	